#!/bin/bash


nSamples=10
executableName="ex1a"


calcValue(){
	t=$1
	n=$2
	mean=0
	sumQuads=0
	
	# calculates mean: sum(x)/n
	for i in `seq 1 $nSamples`
	do
		values[$i]=`./$executableName -t $t -n $n`
		mean=`echo "scale=20; $mean+${values[$i]}" | bc`
	done
	mean=`echo "scale=20; $mean/$nSamples" | bc`
	printf "%s\t" "$mean"
	
	
	
	# calculates stddev: sqrt(1/(n-1) * sum( (x-mean)^2)
	for i in `seq 1 $nSamples`
	do
		sumQuads=`echo "scale=20; $sumQuads+((${values[$i]}-$mean)*(${values[$i]}-$mean))" | bc`
	done
	
	stddev=`echo "scale=20; sqrt($sumQuads/($nSamples-1))" | bc`
	printf "%s\t" "$stddev"
}



rm stat.dat
n=10
# from n= 10 to 10^10
for i in  `seq 1 10`
do
	t=1
	printf "%s\t" "$n"
	# from t=1 to 2^5
	for j in `seq 1 5`
	do
		calcValue $t $n
		t=$((t*2))
	done
	printf "\ti\n"
	n=$((n*10))
done
printf "\n"
